<template>
    <div class="body">
        <div class="box" style="display: flex">
            <div class="left">
                <div class="title"
                     style="width: 140px;height: 62px;text-align: center;line-height: 62px;color: #3D3E3F">
                    <i class="el-icon-s-promotion"></i><span style="margin-left: 5px">消息中心</span>
                </div>
                <div class="common">

<!--                    <el-badge :value="200" :max="99" class="item">-->
<!--                        <el-button size="small" @click="toLove()">收到的赞</el-button>-->
<!--                    </el-badge>-->
                </div>
                <div class="common">
                    <el-badge :value="100" :max="10" class="item">
                        <el-button size="small">收藏</el-button>
                    </el-badge>
                </div>
            </div>
            <div class="right">
                <div style="padding: 10px">
                    <el-card>
                        收藏的文章

                    </el-card>
                    <!--                    <div class="title"-->
                    <!--                         style="width: 100%;height: 42px;background-color: pink;line-height: 42px;padding-left: 8px;color: #666666">-->
                    <!--                    </div>-->
                </div>
                <div style="overflow: auto;width:100%;height: 770px ">

                    <el-card v-for="item in collectionList" class="card-body" style="margin-top: 1px">
                        <div class="base" style="height: 85px;width: 100%;border-bottom: 1px solid #6B757B">
                            <div class="baseitem" style="height: 76px;display: flex">
                                <div class="baseitem-left"
                                     style="width: 46px;text-align: center;padding-top: 10px">
                                    <el-image
                                            style="width: 40px; height: 40px;border-radius: 20px"
                                            :src="item.avatar"
                                            :preview-src-list="[item.avatar]"

                                    ></el-image>
<!--                                    <img style="width: 40px;height: 40px;border-radius: 20px" :src="item.avatar" alt="">-->
                                </div>
                                <!--                                {{// item.avatar}}-->
                                <div class="baseitem-right" style="flex: 1;padding-top: 10px">
                                    <div style="margin-bottom: 10px;margin-left: 10px"><span
                                            style="color: #868762">{{item.blogUserName}}</span> <span
                                            style="margin-left: 15px;font-size: 14px;color: #775050">的文章 <span
                                            style="color: #40A1FF;cursor: pointer"
                                            @click="toDetail(item.blogId)">{{item.blogTitle}}</span>  </span>
                                    </div>
                                    <div style="margin-left: 8px;font-size: 12px;color: #505050">{{item.formatTime}}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </el-card>


                </div>

            </div>
        </div>

    </div>
</template>

<script>
    import jwtDecode from "jwt-decode";
    // import Global from "../assets/js/Global";
    import Global from "../../public/static/Global";

    export default {
        name: "Love",
        data() {
            return {
                collectionList: []
            }
        },
        methods: {
            toLove(){
                this.$router.push({
                    name: 'Love',

                })
            },

            toDetail(id) {
                this.$router.push({
                    name: 'Detail',
                    query: {
                        id: id
                    }
                })
            },
            async getCollectionInfo() {
                const token = localStorage.getItem('token')
                const obj = jwtDecode(token)
                let userId = obj.id;
                const {data: res} = await this.$http.get('/collection/' + userId);

                this.collectionList = res.data
                for (let i = 0; i < res.data.length; i++) {
                    const {data: res1} = await this.$http.get('/comment/avatar/' + res.data[i].blogUserId)
                    res.data[i].avatar = Global.baseUrl + res1.data; // push commentList数组
                }
                this.$forceUpdate();  //强制刷新图片
                console.log(res)
            }
        },
        created() {
            this.getCollectionInfo();
        }
    }
</script>

<style lang="less" scoped>
    .body {
        width: 100%;
        height: 100%;
        background-image: url("https://api.dujin.org/bing/1920.php");
        /*background-size: 80%,80%;*/
        background-repeat: no-repeat;
    }

    .box {
        width: 1230px;
        height: 100vh;
        /*background: pink;*/
        margin: 0 auto;

        .left {
            width: 140px;
            height: 100%;
            background-color: rgba(255, 255, 255, 0.7);
        }

        .right {
            width: 100%;
            /*width: 983px;*/
            /*height: 100%;*/
            min-height: 100vh;
            background-color: rgba(255, 255, 255, 0.7);

        }
    }

    .common {
        width: 140px;
        height: 62px;
        text-align: center;
        /*line-height: 62px;*/
        color: #3D3E3F
    }

    .card-body {
        transition: all 0.4s;

    }

    .card-body:hover {
        transform: scale(0.9);
        box-shadow: 0px 5px 10px 3px #D1D1D1;
    }
</style>